/* 
 *   Date       Developer   Description
 *   
 *
 *   Classname:  zzz.test.component.log.Test01
 * 
 *   Date:   2014-3-10
 * 
 *   The source code contained in this listing is proprietary to
 *   HLJ POST YITONG INFO-NET CO.,LTD.
 * 
 *   Unauthorized copying, adaptation, distribution, use, or display
 *   is strictly prohibited.
 *   This software is Copyright 2014 HLJ POST YITONG INFO-NET CO.,LTD.
 */
package com.titan.demo.camel.sample.component.log;

import org.apache.camel.CamelContext;
import org.apache.camel.ConsumerTemplate;
import org.apache.camel.LoggingLevel;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;

import com.titan.demo.camel.utils.RunCamel;


/**
 * 测试时在文件log4j.properties中增加如下配置
 *      log4j.logger.a=DEBUG, out
 *
 */
public class Test01 {
	public static void main(String[] args) {
        try {
        	RouteBuilder route = createRouteBuilder();
        	createRunCamel().run(route);
        } catch (Exception e) {
            e.printStackTrace();
        }
	}
	
	
	private static RunCamel createRunCamel() {
		return new RunCamel() {
			protected void execute(CamelContext context,
					ProducerTemplate producer, ConsumerTemplate consumer)
					throws Exception {
	            MockEndpoint mock = context.getEndpoint("mock:a", MockEndpoint.class);
	            mock.expectedMessageCount(1);
	            mock.expectedBodiesReceived("Hello World");
	            
	            producer.sendBody("direct:a", "Hello World");
	            
	            mock.assertIsSatisfied();
			}
		};
	}
	
	private static RouteBuilder createRouteBuilder() {
        return new RouteBuilder() {
            public void configure() throws Exception {
                from("direct:a")
                .to("log:a?showBodyType=false&showBody=true&showExchangePattern=false")
                .to("log:zzz.camel.component.log?level=DEBUG")
                .log(LoggingLevel.INFO, this.getClass().getName(), "Processing: ${body}")
                .to("mock:a")
                ;
            }
        };
    }
}

